package modellayer;
import java.util.ArrayList;

/**
 * Write a description of class VareContainer here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class VareContainer
{
    // instance variables - replace the example below with your own
    private static VareContainer instance;
    private ArrayList<Vare> vareList;

    /**
     * Constructor for objects of class VareContainer. This is a test constructor that also
     * creates some obejcts of class Vare and adds them to the ArrayList VareList.
     */
    private VareContainer()
    {
        vareList = new ArrayList<Vare>();
        Vare vare1 = new Vare("Hammer", "Stor hammer af træ og jern", 40, "12345678", "Det der hammer firma", 15, 5, 100, 500);
        Vare vare2 = new Vare("Vandhane", "Diameter: 60mm", 20, "87654321", "De Seje Leverandører", 50, 10, 200, 200);
        Vare vare3 = new Vare("Boremaskine", "100 omdrejninger i minuttet!", 6, "11111111", "Putin Post", 150, 15, 700, 100);
        vareList.add(vare1);
        vareList.add(vare2);
        vareList.add(vare3);
    } 

    /**
     * Singleton for class VareContainer
     */
    public static VareContainer getInstance()
    {
        if(instance == null){
            instance = new VareContainer();
        }
        return instance;
    }

    /**
     * Finds a object Vare with the given String stregkode using a while loop.
     * 
     * @param  stregkode  A string that is used to search for a Vare with the given string.
     * @return     An Object Vare that have the String stregkode as a stregkode attribute, or null if no vare is found.
     */
    public Vare findVare(String stregkode)
    {
        Vare current = null;
        int i=0;
        boolean found = false;
        if(!vareList.isEmpty())
        {
            while (!found && i < vareList.size()){
                if (vareList.get(i).getStregkode().equals(stregkode)){
                    current = vareList.get(i);
                    found = true;
                }

                i++;
            }
        }
        return current;
    }

    /**
     * Adds an object vare to the arraylist vareList.
     * 
     * @param   vare    An object vare to be added to the list.
     */
    public void addVare(Vare vare)
    {
        vareList.add(vare);
    }

}
